<?php
	function getItemClick($itemid){
		//echo ' '.$itemid;
		$html = file_get_contents("http://taoke.alimama.com/spreader/gen_single_code.htm?pid=$itemid");
		if(preg_match("/http:\/\/s\.click\.alimama\.com\/a\/.*?=-/",$html,$match )){
			//echo $match[0];
			//return $match[0];
			header("Location: $match[0]11575228");
		}
		else{
			return false;
		}
	}
	function getStoreClick($storeid){
		$html = file_get_contents("http://taoke.alimama.com/spreader/gen_shop_code.htm?pid=$storeid");
		//echo $html;
		//http://s.click.alimama.com/a/qXw58kgBhL0=-10011550
		if(preg_match("/http:\/\/s\.click\.alimama\.com\/a\/.*?=-/",$html,$match )){
			//echo $match[0];
			//return $match[0];
			header("Location: $match[0]11575228");
		}
		else{
			header("Location: .");
		}		
	}
	
	$a = base64_decode($_GET['a']);
	//跳转
	if(preg_match("/taoapi\.aspx\?pid=(\d+)/",$a,$match)){
		if(false == getItemClick($match[1])){
			if(preg_match("/sid=(\d+)/",$a,$match)){
				getStoreClick($match[1]);
			}
		}
	}
	else if(preg_match("/taoapi\.aspx\?sid=(\d+)/",$a,$match)){
		//taoapi.aspx?sid=11083790&c=50005844
		getStoreClick($match[1]);
	}
	
	//计算url
	if($_SERVER["REQUEST_METHOD"]=="GET"){		
		$url = "http://www.taobangwang.cn/$a";
	}
	else if($_SERVER["REQUEST_METHOD"]=="POST"){
		//搜索
		$category = $_POST['category'];
		$address = $_POST['address'];
		$credit = $_POST['credit'];
		$key = $_POST['key'];
		$key = urlencode($key);
		//echo "http://www.taobangwang.cn/searchp.aspx?c=$category&k=$key&a=$address&m=$credit";
		$url = "http://www.taobangwang.cn/searchp.aspx?c=$category&k=$key&a=$address&m=$credit";		
	}
	$url = base64_encode($url);
?>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html" charset="utf8">
	<link rel="stylesheet" type="text/css" href="http://stdoc.googlecode.com/svn/trunk/tbw/css/index.css"/>
	<link type="text/css" rel="stylesheet" href="http://stdoc.googlecode.com/svn/trunk/tbw/css/main.css" />
	<link type="text/css" rel="stylesheet" href="http://stdoc.googlecode.com/svn/trunk/tbw/css/gridview.css" />
	<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
</head>
<body>
<a href=".">主页</a>
<form action="index.php" method="post">
<div class="search">
    <select name="category">
	<option value="0" selected="selected">所有分类</option>
	<option value="16">女装/女士精品</option>
	<option value="1705">饰品/流行首饰/时尚饰品</option>
	<option value="1801">美容护肤/美体/精油</option>
	<option value="30">男装</option>
	<option value="21">居家日用/厨房餐饮/卫浴洗浴</option>
	<option value="50002766">食品/茶叶/零食/特产</option>
	<option value="50008165">童装/婴儿服/鞋帽/亲子装</option>
	<option value="50006842">箱包皮具/热销女包/男包</option>
	<option value="1625">女士内衣/男士内衣/家居服</option>
	<option value="50008090">3C数码配件市场</option>
	<option value="27">装潢/灯具/五金/安防/卫浴</option>
	<option value="2128">时尚家饰/工艺品/十字绣</option>
	<option value="25">玩具/模型/娃娃/人偶</option>
	<option value="26">汽车/配件/改装/摩托/自行车</option>
	<option value="50010388">运动鞋</option>
	<option value="50012029">运动鞋(NEW)</option>
	<option value="23">古董/邮币/字画/收藏</option>
	<option value="50010788">彩妆/香水/美发/工具</option>
	<option value="50008097">家用电器/hifi音响/耳机</option>
	<option value="50012082">厨房电器</option>
	<option value="50012100">生活电器</option>
	<option value="50008163">床上用品/靠垫/窗帘/布艺</option>
	<option value="50006843">女鞋</option>
	<option value="33">书籍/杂志/报纸</option>
	<option value="2813">成人用品/避孕用品/情趣内衣</option>
	<option value="35">奶粉/尿片/玩具/婴童用品</option>
	<option value="50010728">运动/瑜伽/健身/球迷用品</option>
	<option value="50008168">网络服务/电脑软件</option>
	<option value="50010404">服饰配件/皮带/帽子/围巾</option>
	<option value="50007218">办公设备/文具/耗材</option>
	<option value="11">电脑硬件/台式整机/网络设备</option>
	<option value="50002768">个人护理/保健/按摩器材</option>
	<option value="50007216">鲜花速递/蛋糕配送/园艺花艺</option>
	<option value="50008825">保健品/滋补品/瘦身减肥</option>
	<option value="50008164">家具/家具定制/宜家代购</option>
	<option value="28">ZIPPO/瑞士军刀/眼镜</option>
	<option value="50010387">运动服/运动包/运动配件</option>
	<option value="34">音乐/影视/明星/乐器</option>
	<option value="3009">男鞋</option>
	<option value="50003754">网店装修/物流快递/图片存储</option>
	<option value="50005998">孕妇装/产后瘦身/妈妈用品</option>
	<option value="99">网络游戏虚拟商品交易区</option>
	<option value="50011665">网络游戏装备/游戏币/帐号/代练</option>
	<option value="1512">手机</option>
	<option value="50012081">国货精品手机</option>
	<option value="50005700">品牌手表/流行手表</option>
	<option value="29">宠物/宠物食品及用品</option>
	<option value="50008907">IP卡/网络电话/手机号码</option>
	<option value="14">数码相机/摄像机/图形冲印</option>
	<option value="40">腾讯QQ专区</option>
	<option value="2203">户外/登山/野营/涉水</option>
	<option value="1201">MP3/MP4/iPod/录音笔</option>
	<option value="20">电玩/配件/游戏/攻略</option>
	<option value="1410">闪存卡/U盘/移动存储</option>
	<option value="50012164">闪存卡/U盘/移动存储(NEW)</option>
	<option value="1101">笔记本电脑</option>
	<option value="50009060">旅游度假/打折机票/特惠酒店</option>
	<option value="50004958">移动/联通/小灵通充值中心</option>
	<option value="50011397">珠宝/钻石/翡翠/黄金</option>
	<option value="50008075">演出/旅游/吃喝玩乐折扣券</option>
	<option value="50011150">其它</option>
</select>
    <select name="address">
	<option value="" selected="selected">所在地点</option>
	<option value="安徽">安徽</option>
	<option value="北京">北京</option>
	<option value="福建">福建</option>
	<option value="甘肃">甘肃</option>
	<option value="广东">广东</option>
	<option value="广西">广西</option>
	<option value="贵州">贵州</option>
	<option value="海南">海南</option>
	<option value="海外">海外</option>
	<option value="河北">河北</option>
	<option value="河南">河南</option>
	<option value="湖北">湖北</option>
	<option value="湖南">湖南</option>
	<option value="吉林">吉林</option>
	<option value="江苏">江苏</option>
	<option value="江西">江西</option>
	<option value="辽宁">辽宁</option>
	<option value="内蒙">内蒙</option>
	<option value="宁夏">宁夏</option>
	<option value="青海">青海</option>
	<option value="山东">山东</option>
	<option value="山西">山西</option>
	<option value="陕西">陕西</option>
	<option value="上海">上海</option>
	<option value="四川">四川</option>
	<option value="天津">天津</option>
	<option value="西藏">西藏</option>
	<option value="新疆">新疆</option>
	<option value="云南">云南</option>
	<option value="浙江">浙江</option>
	<option value="重庆">重庆</option>
	<option value="黑龙江">黑龙江</option>
	<option value="澳门">澳门</option>
	<option value="香港">香港</option>
	<option value="台湾">台湾</option>
</select>
    <select name="credit">
	<option value="" selected="selected">所有掌柜</option>
	<option value="250">淘宝心级卖家</option>
	<option value="251">淘宝钻石卖家</option>
	<option value="10001">淘宝皇冠卖家</option>
</select>
    <input type="text" value="" style="width: 160px;" maxlength="20" name="key"/>
    <input type="submit" value="搜索宝贝" />
</div>
</form>

<script type="text/javascript">
	$("option").map(function(){this.value = this.index});
</script>
<?php
	//echo $s;
	echo "<script type=\"text/javascript\">url=\"catch.php?u=$url\"</script>";
?>
<script type="text/javascript">
	function adddata(datafile){
			$("body").append(datafile); 
		}
//alert(url)
$.get(url,adddata,'html')
</script>
</body>
</html>

